<body>
<h1>Scriptella bridge for the JSR 223: Scripting for the Java Platform.</h1>
Allows usage of <a href="http://jcp.org/en/jsr/detail?id=223">JSR 223</a> compatible scripting languages in
ETL &lt;query&gt; and &lt;script&gt; elements.
<p>The driver relies on  <a href="http://java.sun.com/javase/6/docs/api/javax/script/package-summary.html">javax.script</a> package from Java SE 6.
The default language expected by the driver is JavaScript which is bundled with JRE.</p>

<p><b>Important:</b> See <a href="#nashorn_notes">Nashorn JavaScript engine notes</a>
</p>
<h2>General information</h2>
<table>
    <tr>
        <td><b>Driver class:</b></td><td><code>scriptella.driver.script.Driver</code></td>
    </tr>
    <tr>
        <td><b>URL:</b></td><td>URL of the file to read from and send output to. URIs are resolved relative to a script file.
    If url is not specified console (<code>System.in/out</code>) is used.</td>
    </tr>
    <tr>
        <td><b>Runtime dependencies:</b></td><td><b>Java SE 6</b> is required. Additional dependencies are specific to a scripting language.</td>
    </tr>
</table>
<h2>Driver Specific Properties</h2>
<table border="1">
    <tr>
        <th>Name</th>
        <th>Description</th>
        <th>Required</th>
    </tr>
    <tr>
        <td>language</td>
        <td>Language used in scripts and queries.</td>
        <td>No, the default language is <code>JavaScript</code>.</td>
    </tr>
    <tr>
        <td>encoding</td>
        <td>Specifies charset encoding of a character stream specified by an url connection parameter.</td>
        <td>No, the system default encoding is used.</td>
    </tr>
</table>

<h2>Query and Script Syntax</h2>
This driver does not impose any limitations on a language syntax. See <a href="https://scripting.dev.java.net">JSR-223 script engines</a>
project for more details on supported languages.
<p>
    Scripts and queries can reference variables from ancestor elements. Declared variables are
    exposed to nested elements.
</p>
<p>Implicit variable <code>query</code> is available in &lt;query&gt; elements. This variable
should be used to produce a result set:</p>
<code>
<pre>
    &lt;query&gt;&lt;![CDATA[
        var v1 = 'This variable is visible in a child script';
        for (var i = 0; i < 10; i++) {
            query.next(); // Triggers execution of a child script.
        }]]&gt;
        &lt;script&gt;
            ......
            v2 = v1 + '!';
            ......
        &lt;/script&gt;
    &lt;/query&gt;
</pre>
See <a href="ParametersCallbackMap.html">ParametersCallbackMap class Javadoc</a> for more details.
</code>
<h2><a name="nashorn_notes">JDK 8 Nashorn JavaScript Engine notes<a></h2>
Due to Nashorn being <a href="https://openjdk.java.net/jeps/335">deprecated in JDK11</a> and its incompatibilities with Scriptella,
please use <a href="https://developer.mozilla.org/en-US/docs/Mozilla/Projects/Rhino">Rhino</a>
with javax.script adapter (language=rhino in connection properties).
<br>If you use Maven, add cat.inspiracion:rhino-js-engine dependency.
<br>Jars can be found in the <a href="https://github.com/scriptella/scriptella-etl/tree/master/lib">lib directory</a> of the Github repository.

<p>Example of the connection declaration:
<pre>
    &lt;connection driver="script"&gt;
        language=rhino
    &lt;/connection&gt;
</pre>
For more details see <a href="https://github.com/scriptella/scriptella-etl/issues/2">GitHub Issue</a>
<a name="examples"></a>
<h2>Examples</h2>
The following query executes a child script 10 times. As the result of execution 10 records
are inserted into a database table. Additionally a log file log.txt is produced.
<code><pre>
&lt;connection id="script" driver="script"/&gt;
&lt;connection id="out" driver="oracle" url="jdbc:oracle:thin:@localhost:1521:DB"/&gt;
&lt;connection id="log" driver="script" url="log.txt"/&gt;

&lt;query connection-id="script"&gt;
    &lt;![CDATA[
    for (var i = 0; i < 10; i++) {
        login = 'login' + i;
        //You can instantiate Java objects and invoke static methods
        var now = new java.sql.Timestamp(java.lang.System.currentTimeMillis());
        query.next(); //Executes a child script element
    }]]&gt;

    &lt;!-- Inserts a parameterized row into a database --&gt;
    &lt;script connection-id="out"&gt;
        INSERT INTO Table(ID, Login, Login_Time) VALUES (?i, ?login, ?now);
    &lt;/script&gt;
    
    &lt;!-- Logs the message using MessageFormat class and parent context variables --&gt;
    &lt;script connection-id="log">
        // create Java String array of 2 elements
        var a = java.lang.reflect.Array.newInstance(java.lang.Object, 2)
        a[0] = now;a[1] = i;
        println(format.format(a));
    &gt;/script>
&lt;/query&gt;

</pre></code>
</body>